﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.数据访问对象模式
{
    public class StudentDaoImpl : IStudentDao
    {
        List<Student> students;

        public StudentDaoImpl()
        {
            students = new List<Student>();
            Student student1 = new Student("Robert", 0);
            Student student2 = new Student("John", 1);
            students.Add(student1);
            students.Add(student2);
        }

        public void DeleteStudent(Student student)
        {
            students.Remove(student);
            Console.WriteLine("Student: Roll No " + student.RollNo + ",deleted from database");
        }

        public Student GetStudent(int rollNo)
        {
            return students.Find(item=>item.RollNo==rollNo);
        }

        public List<Student> GetStudents()
        {
            return students;
        }

        public void UpdateStudent(Student student)
        {
            students.Find(item => item.RollNo == student.RollNo).Name = student.Name;
            Console.WriteLine("Student: Roll No " + student.RollNo + ",updated in the database");
        }
    }
}
